package com.agmte.api.common.crud.tableAutoCreate;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class GenericTypeChecker {
    public static void main(String[] args) throws Exception {
        List<String> stringList = new ArrayList<>();

        // 获取字段的泛型类型（假设是类字段）
        Field field = GenericTypeChecker.class.getDeclaredField("tableInfos");
        Type genericType = field.getGenericType();

        if (genericType instanceof ParameterizedType) {
            ParameterizedType pType = (ParameterizedType) genericType;
            Type[] actualTypeArgs = pType.getActualTypeArguments();

            if (actualTypeArgs.length > 0 && actualTypeArgs[0] == String.class) {
                System.out.println("泛型类型是String");
            }
        }
    }

    // 测试用字段
    private static List<String> tableInfos = new ArrayList<>();
}